package com.ruoyi.internet.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.internet.domain.IntService;
import com.ruoyi.internet.service.IIntServiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 服务模块Controller
 *
 * @author cjie
 * @date 2021-08-16
 */
@Api(tags = " 服务模块")
@RestController
@RequestMapping("/intService")
public class IntServiceController extends BaseController {
    @Autowired
    private IIntServiceService intServiceService;

    /**
     * 查询服务模块列表
     */
    @ApiOperation(value="查询服务模块列表", notes="查询服务模块列表")
    @PreAuthorize(hasPermi = "internet:intService:list")
    @GetMapping("/list")
    public TableDataInfo list(IntService intService) {
        startPage();
        List<IntService> list = intServiceService.selectIntServiceList(intService);
        return getDataTable(list);
    }

    /**
     * 导出服务模块列表
     */
    @ApiOperation(value="导出服务模块列表", notes="导出服务模块列表")
    @Log(title = "服务模块", businessType = BusinessType.EXPORT)
    @PreAuthorize(hasPermi = "internet:intService:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, IntService intService) throws IOException {
        List<IntService> list = intServiceService.selectIntServiceList(intService);
        ExcelUtil<IntService> util = new ExcelUtil<IntService>(IntService.class);
        util.exportExcel(response, list, "服务模块数据");
    }
    /**
     * 获取服务模块详细信息
     */
    @ApiOperation(value="获取服务模块详细信息", notes="获取服务模块详细信息")
    @PreAuthorize(hasPermi = "internet:intService:query")
    @GetMapping(value = "/info/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(intServiceService.selectIntServiceById(id));
    }

    /**
     * 新增服务模块
     */
    @ApiOperation(value="新增服务模块", notes="新增服务模块")
    @Log(title = "服务模块", businessType = BusinessType.INSERT)
    @PreAuthorize(hasPermi = "internet:intService:add")
    @PostMapping
    public AjaxResult add(@RequestBody IntService intService) {
        return toAjax(intServiceService.insertIntService(intService));
    }

    /**
     * 修改服务模块
     */
    @ApiOperation(value="修改服务模块", notes="修改服务模块")
    @Log(title = "服务模块", businessType = BusinessType.UPDATE)
    @PreAuthorize(hasPermi = "internet:intService:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody IntService intService) {
        return toAjax(intServiceService.updateIntService(intService));
    }

    /**
     * 删除服务模块
     */
    @ApiOperation(value="删除服务模块", notes="删除服务模块")
    @ApiImplicitParam(name = "ids", value = "服务模块ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @Log(title = "服务模块", businessType = BusinessType.DELETE)
    @PreAuthorize(hasPermi = "internet:intService:remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(intServiceService.deleteIntServiceByIds(ids));
    }
}
